package flc.ast.widget.time;

import android.annotation.SuppressLint;
import android.appwidget.AppWidgetManager;
import android.content.Context;
import android.graphics.Color;
import android.widget.RemoteViews;

import com.blankj.utilcode.util.TimeUtils;

import java.text.SimpleDateFormat;

import flc.ast.R;
import flc.ast.utils.AppSpUtils;

public class Time5Widget extends BaseTimeWidget {


    public Time5Widget(int appWidgetId) {
        super(appWidgetId);
    }

    @Override
    protected void onUpdate(Context context) {
        @SuppressLint("RemoteViewLayout") RemoteViews remoteViews =
                new RemoteViews(context.getPackageName(), R.layout.widget_time5);
        //准备数据
        String date = TimeUtils.getNowString(new SimpleDateFormat("MM/dd EEEE"));
        String time = TimeUtils.getNowString(new SimpleDateFormat("HH:mm"));
        //更新显示数据
        String time5Color = AppSpUtils.getTime5Color();
        remoteViews.setTextViewText(R.id.tvTime5Date, date);
        remoteViews.setTextViewText(R.id.tvTime5Time, time);
        remoteViews.setTextColor(R.id.tvTime5Date, Color.parseColor(time5Color));
        remoteViews.setTextColor(R.id.tvTime5Time, Color.parseColor(time5Color));

        remoteViews.setInt(R.id.llTime5Bg, "setBackgroundColor", AppSpUtils.getTime5Bg());

        AppWidgetManager.getInstance(context).updateAppWidget(appWidgetId, remoteViews);
    }
}